class LineItem < ActiveRecord::Base
  belongs_to :order
  belongs_to :product

  def self.from_cart_item(cart_item)
    li = self.new
    li.product        = Product.find(cart_item.product_id)
    li.quantity       = cart_item.quantity
    li.price          = cart_item.price
    li
  end

  def total_price
    return 0 if !self.product
    self.price * self.quantity
  end
end
